using FluentAssertions;
using CollabApp.Application.Interfaces;
using CollabApp.Domain.Entities.Auth;
using CollabApp.Domain.Repositories;
using System.Dynamic;
using Moq;
using System.Threading;

namespace CollabApp.Application.Tests;

public static class AuthServiceAssertions
{
    public static void ShouldReturnSuccess(dynamic result)
    {
        ((int)result.Code).Should().Be(1000);
    }

    public static void ShouldReturnUserNotFound(dynamic result)
    {
        ((int)result.Code).Should().Be(1001);
    }

    public static void ShouldReturnIncorrectPassword(dynamic result)
    {
        ((int)result.Code).Should().Be(1002);
    }

    public static void ShouldReturnBannedUser(dynamic result)
    {
        ((int)result.Code).Should().Be(1003);
    }

    public static void ShouldHaveValidToken(dynamic result, Mock<IJwtTokenService> jwtTokenService, User user)
    {
        jwtTokenService.Verify(x => x.GenerateToken(user.Id, user.Username), Times.Once);
    }

    public static void ShouldHaveUpdatedUser(Mock<IRepository<User>> userRepository)
    {
        userRepository.Verify(x => x.UpdateAsync(It.IsAny<User>()), Times.Once);
        userRepository.Verify(x => x.SaveChangesAsync(It.IsAny<CancellationToken>()), Times.Once);
    }
}
